<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>添加文章</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"><!-- 确保适当的绘制和触屏缩放 -->
    <link rel="stylesheet" href="{$url_css}bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="{$url_css}admin.css" type="text/css">
    <link rel="stylesheet" href="{$url_css}tagcate.css" type="text/css">

    <script type="text/javascript" src="{$url_js}jquery-2.2.0.min.js"></script>
    <script type="text/javascript" src="{$url_js}bootstrap.min.js"></script>
    <script type="text/javascript" src="{$url_public}editor/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="{$url_public}editor/ckfinder/ckfinder.js"></script>
    <script type="text/javascript" src="{$url_js}tagcate.js"></script>
    <script type="text/javascript" src="{$url_js}calendar/WdatePicker.js"></script>
    <script type="text/javascript" src="{$url_js}AutoTips.js"></script>
    <script type="text/javascript" src="{$url_js}jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="{$url_js}jquery-ui.min.js"></script>
    <script type="text/javascript" src="{$url_js}jquery.contextmenu.r2.js"></script>
    <style type="text/css">
        {literal}
        .cover_img_div input[type="file"] {
            cursor: inherit;
            opacity: 0;
            z-index: 99;
        }
        .atlas1_img_div input[type="file"] {
            cursor: inherit;
            opacity: 0;
            z-index: 99;
        }
        .div-child-left {
            position:absolute;
            top:0px;
            left:0;
            width:0px;
        }
        .cover_img_div{min-width:163px; position:relative;float:left;margin:4px;border:1px solid #ddd;border-radius:4px;text-align: center;}
        .atlas_img_div {width:360px; height: 240px; position:relative; float:left; border:1px solid #ddd; border-radius:4px; text-align: center;}
        .input-file {position: absolute;left: 0;bottom:0;width: 85px;z-index: 1;}
        .delete_btn {position: absolute;right: 0;bottom:0;width: 55px;z-index: 1;}
        .div_btn{ width: 100%;}
        .sort_input{}
        .sort_div{margin: 10px 75px; float: left;}
        .div_btn input{ width: 7%;}
        div.cate-wrapper ul.cate-list{max-height: 400px; overflow: auto}
        .atlas_img_div img{height: 240px}
        /*
         * user auto tips css
         */
        ul { list-style: none outside none; margin: 0px; padding: 0px; -webkit-padding-start: 0px;}
        .recipients-tips{ font-family:Tahoma, Arial;position:absolute; background:#fff; z-index:2147483647; padding:2px; border:1px solid #ccc; display:none; margin: 0px;}
        .recipients-tips li a{display:block; padding:5px 10px; color:#333; cursor:pointer; font-family:Tahoma, Arial;}
        .recipients-tips li a:hover{text-decoration: none;}
        .recipients-tips li a em{font-weight:700; color:#000; font-family:Tahoma, Arial;}
        .autoSelected{background:#f4f4f4; font-family:Tahoma, Arial;}
        {/literal}
    </style>
</head>
<body>

<div class="container" style="width:96%">
    <table id="myformtable" class="table table-bordered table-striped" align="center">
        <input type="hidden" name="ArticleId" value="{$info['ArticleId']}"/>
        <input type="hidden" name="page" value="{$page}"/>
        <input type="hidden" name="urlfrom" value="{$urlfrom}"/>
        <input type="hidden" name="uri" value="{$uri}"/>
        <input type="hidden" name="search_siteid" value="{$search_siteid}"/>
        <input type="hidden" name="search_title" value="{$search_title}"/>
        <input type="hidden" name="search_start_itemid" value="{$search_start_itemid}"/>
        <input type="hidden" name="search_end_itemid" value="{$search_end_itemid}"/>
        <input type="hidden" name="search_catid" value="{$search_catid}"/>
        <input type="hidden" name="search_status" value="{$search_status}"/>
        <tbody>
        <tr>
            <td colspan="2"><h5>{($info)?'编辑':'添加'}文章，其中标题、分类、状态、内容、封面图为必填</h5></td>
        </tr>

        {if !empty($info) && !empty($similar_title)}
            <tr>
                <td class="col-xs-2">相似标题：</td>
                <td id="similar_title">
                    {foreach $similar_title as $v}
                        <a href="?do=Edit&id={$v[0]}">{$v[1]|html}</a>
                        &nbsp;(频道：{$v[2]}，最后修改时间：{$v[3]})<br>
                    {/foreach}
                </td>
            </tr>
        {/if}
        <tr>
            <td><span style="color: red">*</span>文章标题：</td>
            <td><input type="text" class="form-control" id="Title" name="Title" value="{$info['Title']|html}"
                       placeholder="文章标题"
                       style="width: 85%;"/>
            </td>
        </tr>
        <tr>
            <td class="col-xs-2">文章站点：</td>
            <td>
                <div class="form-inline">
                    <div class="form-group">
                        <select id="SiteId" name="SiteId" class="form-control" style="width: 300px;">
                            {foreach $site as $v}
                                <option value="{$v.id}" {($info['SiteId']==$v['id'])?'selected="selected"':''}>{$v.name}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group">
                        <input type="text" class="form-control" id="Alias" name="Alias" placeholder="站点别名" value="{$info['SiteName']}"/>
                        站点别名优先显示
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>描述：</td>
            <td>
                <textarea rows="3" cols="2" class="form-control" id="Description" name="Description" placeholder="描述"
                          style="width: 80%;">{$info['Description']|html}</textarea>
            </td>
        </tr>
        <tr>
            <td class="col-xs-2"><span style="color: red">*</span>文章类型：</td>
            <td>
                <select id="Type" name="Type" class="form-control" style="width: 300px;" {if !empty($info)}disabled="true"{/if}>
                    {foreach $type as $v}
                        <option value="{$v.id}" {($info['Type']==$v['id'])?'selected="selected"':''}>{$v.name}</option>
                    {/foreach}
                </select>
            </td>
        </tr>

        <tr id="tr_TypeLen" {(!in_array($info['Type'], [3,7])||!isset($info['Type']))?'style="display: none"':''}>
            <td><span style="color: red">*</span>{($info['Type']==7)?'音频':'视频'}时长(s)：</td>
            <td><input type="text" class="form-control" id="TypeLen" name="TypeLen" value="{$info['TypeLen']}"
                       placeholder="{($info['Type']==7)?'音频':'视频'}时长"
                       style="width: 300px;"/>
            </td>
        </tr>
        <tr id="tr_TypeData" {(!in_array($info['Type'], [3,7])||!isset($info['Type']))?'style="display: none"':''}>
            <td>
                <span style="color: red">*</span>类型数据：<br/>
	            {($info['Type']==7)?'音频':'视频'}完整地址,仅支持{($info['Type']==7)?'MP3':'MP4'}
            </td>
            <td>
                <div class="form-inline">
                    <div class="form-group" style="width: 70%;">
                        <label for="video">类型数据</label>
                        <input type="text" class="form-control" id="TypeData" name="TypeData"
                               value="{$info['TypeData']}" placeholder="类型数据" style="width: 100%;"/>
                    </div>

                    <div class="form-group">
                        <label for="video">上传视频</label>
                        <form action="?do=UploadVideo" enctype="multipart/form-data" method="POST" target="upframe">
                            <input type="file" class="form-control" id="video" name="video" value="上传视频"
                                   style="width: 200px;" accept=".mp4" onchange="videoChange()"/>
                        </form>
                    </div>
                </div>
            </td>
        </tr>

        <tr>
            <td class="col-xs-2">封面(列表展示)类型：</td>
            <td>
                <label class="radio-inline"><input type="radio" name="CoverType"
                                                   value="0" {($info['CoverType'] == 0 || !isset($info['CoverType']))?'checked':''} />默认(无图、小单图或3图)</label>
                 <label {if $info['Type'] != 3} style="display: none"{/if} id="radio_id" class="radio-inline"><input type="radio" name="CoverType"
                                                   value="1" {($info['CoverType'] == 1)?'checked':''} />单张大图</label>
            </td>
        </tr>
        <tr>
            <td>
                封面图：<br/>
                支持：jpg，png<br/>
                最大2M，最多3张<br/>
                尺寸至少320*240<br/>
            </td>
            <td>
                <table>
                    <iframe name='upframe' id="upframe" style='display:none'></iframe>
                    <tr>
                        <td>
                            {if !empty($info['Covers'])}
                                {foreach $info['Covers'] as $i => $v}
                                    <div class="cover_img_div">
                                        <img id="preview_img_{$i}" src="{$v}" style="width:auto;max-width:600px;height:160px;">
                                        <form action="?do=UploadImg&id={$i}" enctype="multipart/form-data" method="POST"
                                              target="upframe">
                                            <div class="input-group">
                                                <input type="hidden" name="file_name" value="fileimg_{$i}">
                                                <input class="form-control" style="width: 99px;" type="file"
                                                       name="fileimg_{$i}" accept=".jpg,.png"
                                                       onchange="fileChange('{$i}')"> &nbsp;
                                            </div>
                                        </form>
                                        <a class="btn btn-default input-file" href="javascript:void(0);">选择图片</a>
                                        <a class="btn btn-default delete_btn" onclick="delCode($(this),'{$i}');">删除</a>
                                        <input type="hidden" id="cover_{$i}" name="cover[]" value="{$v}"/>
                                    </div>
                                {/foreach}
                            {/if}
                            <p style="float:left;margin:160px 0 0 5px;">
                                <button class="btn btn-primary" id="add_cover" onclick="addCode($(this))">新增</button>
                            </p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>

        <tr id="article_content" {($info['Type']==2)?'style="display: none"':''}>
            <td><span style="color: red">*</span>内容：</td>
            <td>
                <textarea id="Content" name="Content">{$info['Content']}</textarea><br>
                <input id="picture_info" name="picture_info" type="button" class="btn btn-primary" value="自动下载第三方图片"/>
                <input id="preview_content" name="preview_content" type="button" class="btn btn-primary" onclick="preview('{$info['Encryption']}')" value="预览文章"/>
            </td>
        </tr>

        <tr id="atlas_content" {($info['Type']!=2)?'style="display: none"':''}>
            <td><span style="color: red">*</span>图集内容：</td>
            <td id="atlas_height">
                <div class="contextMenu" id="myMenu1" style="display: none;">
                    <ul>
                        <li id="open">设为封面图</li>
                    </ul>
                </div>
                <div id="div_height" style="min-height: 50px">
                    <div style="margin-left: 5px">
                        <span><span><span><input type="button" class="btn btn-primary" value="新增" onclick="addAtlas($(this),1)"/></span></span></span>
                    </div>
                    <div id="module_list" class="ui-sortable">
                        {if !empty($info['Content']) && $info['Type'] == 2}
                            {foreach $info['Content'] as $k => $v}
                                <div style="margin: 10px 75px; float: left;" class="sort_div modules">
                                    <div style="width: 450px" class="m_title">
                                        <input type="hidden" id="atlas1_img_{$k}" name="atlas1_img[]" value="{$v['img']}"/>
                                        <form action="?do=Atlas" enctype="multipart/form-data" method="post" target="upframe" class="form-inline">
                                            <div class="input-group" style="margin: 1px 0px">
                                                <div class="input-group-addon">选择图片</div>
                                                <div class="atlas_img_div form-group" style="position: relative">
                                                    <img id="atlas_img_{$k}" src="{$v['img']}" alt="" style="max-width: 360px;max-height: 240px"/>
                                                    <div class="form-group atlas1_img_div div-child-left">
                                                        <input type="hidden" name="atlas" value="fileimg_{$k}">
                                                        <input style="width: 360px; height: 240px" type="file" class="form-control input-file" name="fileimg_{$k}" id="fileimg_{$k}" onchange="$(this).parents('form').submit();"/>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                        <div class="input-group" style="margin: 1px 0px">
                                            <div class="input-group-addon">图片文字</div>
                                            <textarea style="width: 300px; height: 123px" type="text" class="form-control" name="atlas_text[]" id="atlas_text">{$v['text']}</textarea>
                                            <div>
                                                <input type="button" class="btn btn-primary" value="新增" onclick="addAtlas($(this))" style="margin-top: 10px; margin-left: 5px"/>
                                                <input type="button" class="btn btn-default" value="删除" onclick="atlasdelCode($(this))" style="margin-top: 40px; margin-left: 5px"/>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            {/foreach}
                        {/if}
                    </div>
                </div>
            </td>

        </tr>

        <tr>
            <td>
                <span style="color: red">*</span>标签：<br/>
                填写自定义标签用 空格(或者英文逗号) 分隔
            </td>
            <td>
                <a class="btn btn-default" id="pop_tag_btn">选择标签</a>
                <button class="btn btn-default" onclick="getSplit()" id="get_split">自动提取文章标签beta</button>
                <br/><br/>
                <textarea class="form-control" rows="" cols="" id="tag" name="tag">{$info['tags']}</textarea>
            </td>
        </tr>
        <tr>
            <td>
                <span style="color: red">*</span>展示用标签：<br/>
                填写自定义标签用 空格(或者英文逗号) 分隔
            </td>
            <td>
                <textarea class="form-control" rows="" cols="" id="ViewTag" name="ViewTag">{$info['ViewTag']}</textarea>
            </td>
        </tr>
        <tr>
            <td class="col-xs-2"><span style="color: red">*</span>所属她她号：</td>
            <td>
                <div class="form-inline">
                    <div class="form-group">
                        <input type="hidden" id="TaTaUserId" name="TaTaUserId"  value="{$info['TaTaUserId']}"/>
                        <input type="text" class="form-control" id="TaTaName" value="{$info['TaTaName']}"
                               readonly="readonly"
                               style="width: 300px;"/>
                    </div>
                    <div class="form-group" style="position: relative">
                        <input type="text" class="form-control" id="search_tatahao_btn" placeholder="搜索她她号" style="width: 300px;"/>
                        <div class="has-success" id="search_tatahao_list" style="position: absolute; z-index: 9999; padding:2px 10px;background: #ffffff; border: solid 1px #abcdef; display: none;">
                            <div id="search_tatahao_list_info">
                                <div class="checkbox">
                                    <label>
                                        <input type="radio" value="option1">
                                        radio with success
                                    </label>
                                </div>
                            </div>
                            <button class="btn btn-default" style="margin-top: 10px;" id="search_tatahao_submit">确定</button>
                        </div>
                    </div>
                </div>
            </td>
        </tr>
        <script type="text/javascript">
            $(function() {
                $('#search_tatahao_btn').on('keyup', function () {
                    var str = $.trim($(this).val());
                    if (str !='') {
                        $.get('?do=SearchTaTaHao&str='+str, function (data) {
                            var html = '';
                            if(data.total > 0) {
                                for (var i=0,l=data.list.length;i<l;i++) {
                                    html += '<div class="checkbox" style="min-width: 172px;"><label><input type="radio" value="'+ data.list[i].TaTaUserId+'" name="search_tatahao">'+ data.list[i].TaTaName +'</label></div>';
                                }
                            } else {
                                html = '<div class="checkbox" style="min-width: 172px;"><label>暂无结果</label></div>';
                            }
                            $('#search_tatahao_list_info').html(html);
                            $('#search_tatahao_list').show();
                        }, 'json');
                    }
                });
                $('#search_tatahao_submit').on('click', function () {
                    var taid = $('input[name="search_tatahao"]:checked').val();
                    var taname = $('input[name="search_tatahao"]:checked').parent().html().replace(/<\/?.+?>/g,"");
                    $('#TaTaUserId').val(taid);
                    $('#TaTaName').val(taname);
                    $('#search_tatahao_list').hide();
                });
            });
        </script>
        <tr>
            <td>作者：</td>
            <td><input type="text" class="form-control" id="Author" name="Author" value="{$info['Author']}"
                       placeholder="作者"
                       style="width: 300px;"/>
            </td>
        </tr>
        <tr>
            <td>来源地址：</td>
            <td><input type="text" class="form-control" id="FromUrl" name="FromUrl" value="{$info['FromUrl']}"
                       placeholder="来源地址"
                       style="width: 350px;"/>
            </td>
        </tr>
        <tr>
            <td>更新时间：(用于列表排序)</td>
            <td><input type="text" class="form-control" id="UpdateTime" name="UpdateTime" value="{$info['UpdateTime']}"
                       placeholder="更新时间" style="width: 160px;"
                       onFocus="WdatePicker({literal}{dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'}{/literal});" value="" readonly/>
            </td>
        </tr>
        <tr>
            <td>状态：</td>
            <td>
                <label class="radio-inline"><input type="radio" name="Status"
                                                   value="1" {($info['Status'] == 1)?'checked':''} />正常</label>
                <label class="radio-inline"><input type="radio" name="Status"
                                                   value="2" {($info['Status'] == 2 || !isset($info['Status']))?'checked':''} />待审核</label>
                <label class="radio-inline"><input type="radio" name="Status"
                                                   value="3" {($info['Status'] == 3)?'checked':''} />审核不通过</label>
                <label class="radio-inline"><input type="radio" name="Status"
                                                   value="4" {($info['Status'] == '0')?'checked':''} />隐藏</label>
                <label class="radio-inline"><input type="radio" name="Status"
                                                   value="8" {($info['Status'] == 8)?'checked':''} />关键词隐藏</label>
            </td>
        </tr>
        <tr>
            <td class="col-xs-2"><span style="color: red">*</span>文章分类：</td>
            <td>
                <select id="CateId" name="CateId" class="form-control" style="width: 300px;">
                    {foreach $cate as $v}
                        <option value="{$v.id}" {($info['CateId']==$v['id'])?'selected="selected"':''}>{$v.name}</option>
                    {/foreach}
                </select>
            </td>
        </tr>
        <tr>
            <td>最后一次操作管理员用户ID:</td>
            <td id="AdminUserId" name="AdminUserId" class="col-xs-10">
                {if !empty($info['AdminUserId'])}
                    {$info['AdminUserId']}
                {/if}
                {if !empty($info['AdminUserId']) && !empty($adminusername)}
                    ({$adminusername})
                {/if}
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                {if !empty($info['AdminUserId'])}
                    <label class="radio-inline">
                        <input name="change" type="checkbox" value="no"/>&nbsp;不更改管理员用户ID
                    </label>
                {/if}
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>
                <div id="div_btn" class="div_btn">
                    <input type="button" onclick="From_submit(this);" class="btn btn-primary" value="保存"/>
                    <input type="reset" class="btn btn-warning" value="重置"/>
                    {if $info}
                        <input type="button" class="btn btn-default" onclick="javascript:history.go(-1)" value="返回"/>
                    {/if}
                </div>
            </td>
        </tr>
        </tbody>
    </table>
</div>
<div class="modal" id="pop_tag" style="width:1000px;display: none">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width: 900px">
            <div class="modal-header">
                <button type="button" class="close" data-job="close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">标签选择器</h4>
                <div class="col-xs-3" style="position: absolute; top:15px; left: 300px;">
                    <input type="text" class="form-control" placeholder="搜索标签" id="search_tag_btn">
                    <div class="has-success" id="search_tag_list" style="position: absolute; z-index: 9999; padding:0 10px;background: #ffffff; border: solid 1px #abcdef; display: none;">
                        <div id="search_tag_list_info">
                        <!--
                        <div class="checkbox">
                            <label>
                                <input type="checkbox" value="option1">
                                Checkbox with success
                            </label>
                        </div>
                        <button class="btn btn-default" style="margin-top: 8px;" type="button">确定</button>
                        -->
                        </div>
                        <button class="btn btn-default" style="margin-top: 8px;" id="search_tag_submit">确定</button>
                    </div>
                </div>
            </div>
            <div class="modal-body" id="tag_content">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-job="close">保存</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
	var sensitiveWord = '{$sensitiveWord}';

    $(function () {
        var box = document.getElementById('pop_tag');
        box.onmousedown = function (event) {
            var e = event || window.event,
                    t = e.target || e.srcElement,
                    //鼠标按下时的坐标x1,y1
                    x1 = e.clientX,
                    y1 = e.clientY,
                    //鼠标按下时的左右偏移量
                    dragLeft = this.offsetLeft,
                    dragTop = this.offsetTop;
            document.onmousemove = function (event) {
                var e = event || window.event,
                        t = e.target || e.srcElement,
                        //鼠标移动时的动态坐标
                        x2 = e.clientX,
                        y2 = e.clientY,
                        //鼠标移动时的坐标的变化量
                        x = x2 - x1,
                        y = y2 - y1;
                box.style.left = (dragLeft + x) + 'px';
                box.style.top = (dragTop + y) + 'px';
            }
            document.onmouseup = function () {
                this.onmousemove = null;
            }
        }
    });
    (function () {
        var pop_tag = $('#pop_tag'),
                getArrTag = function () {
                    var tag = $.trim($('#tag').val()),
                            tag_uniq = [];
                    if (tag.length > 0) {
                        var tag_arr = tag.split(' '),
                                tag_obj = {};
                        for (var i = 0, len = tag_arr.length; i < len; i++) {
                            tag_obj[tag_arr[i]] = tag_arr[i];
                        }
                        for (var x in tag_obj) {
                            tag_uniq.push(tag_obj[x]);
                        }
                    }
                    return tag_uniq;
                };
        var tc = hd.tools.tagcate({
            'born': function ($w) {
                $('#tag_content').append($w);
                pop_tag.find("[data-job=close]").on('click', function () {
                    pop_tag.hide();
                });
                this.select(getArrTag());
            },
            'onSelect': function (cates) {
                var old_tag = getArrTag(), name;
                for (var k = 0, l = cates.length; k < l; k++) {
                    name = cates[k];
                    if ($.inArray(name, old_tag) == -1) {
                        old_tag.push(name);
                    }
                }
                $('#tag').val(old_tag.join(' '));
            },
            'onCancel': function (cates) {
                var old_tag = getArrTag(), name;
                for (var k = 0, l = cates.length; k < l; k++) {
                    name = cates[k];
                    pos = $.inArray(name, old_tag);
                    if (pos != -1) {
                        delete old_tag[pos];
                    }
                }
                $('#tag').val(old_tag.join(' '));
            }
        });
        $('#pop_tag_btn').on('click', function () {
            tc.clear();
            tc.select(getArrTag());
            pop_tag.show()
        });
        $('#search_tag_btn').on('keyup', function () {
            var str = $.trim($(this).val());
            if (str !='') {
                $.get('?do=SearchTag&str='+str, function (data) {
                    var html = '';
                    if(data.total > 0) {
                        for (var i=0,l=data.list.length;i<l;i++) {
                            html += '<div class="checkbox" style="min-width: 172px;"><label><input type="checkbox" value="'+ data.list[i].TagName+'" name="search_tag">'+ data.list[i].TagName +'</label></div>';
                        }
                    } else {
                        html = '<div class="checkbox" style="min-width: 172px;"><label>暂无结果</label></div>';
                    }
                    $('#search_tag_list_info').html(html);
                    $('#search_tag_list').show();
                }, 'json');
            }
        });
        $('#search_tag_submit').on('click', function () {
            var chk_value =[];
            $('input[name="search_tag"]:checked').each(function(){
                chk_value.push($(this).val());
            });
            if (chk_value) {
                //tc.onSelect(chk_value);
                var old_tag = getArrTag(), name;
                for (var k = 0, l = chk_value.length; k < l; k++) {
                    name = chk_value[k];
                    if ($.inArray(name, old_tag) == -1) {
                        old_tag.push(name);
                    }
                }
                $('#tag').val(old_tag.join(' '));
            }
            $('#search_tag_list').hide();
        });
    })();
</script>
{literal}
    <script type="text/javascript">
        $('#Type').change(function () {
            var type = $(this).val();
            if (type == 1) {
                $('#tr_TypeLen').hide();
                $('#tr_TypeData').hide();
                $('#atlas_content').hide();
                $('#article_content').show();
                $('#radio_id').css('display', 'none');
            } else if (type == 2) {
                $('#tr_TypeLen').hide();
                $('#tr_TypeData').hide();
                $('#article_content').hide();
                $('#atlas_content').show();
                $('#radio_id').css('display', 'none');
            } else {
                $('#tr_TypeLen').show();
                $('#tr_TypeData').show();
                $('#article_content').show();
                $('#atlas_content').hide();
                $('#radio_id').css('display', '');
            }
        });
        function getSplit() {
            content = editor.document.getBody().getHtml();
            content = trimStr(content);
            if (content == '' || content == '<p><br></p>') {
                top.sweetAlert('文章内容不能为空', '', 'error');
            } else {
                $.post('?do=getSplit', {'content': content}, function (data) {
                    if (data == 0) {
                        top.sweetAlert('文章内容为空', '', 'error');
                    } else if (data == -1) {
                        top.sweetAlert('自动提取关键字失败', '', 'error');
                    } else {
                        var tag = $.trim($('#tag').val());
                        $('#tag').val(tag + ' ' + data);
                    }
                })
            }
        }
        /**
         * 图集添加
         */
        function addAtlas(obj, type){

            var time = new Date().getTime();
            var atlas_height = '';
            var div_height = '';
            var tpl =
                    '<div style="margin: 10px 75px; float: left;" class="sort_div modules">' +
                    '<div style="width: 450px" class="m_title">' +
                    '<input type="hidden" id="atlas1_img_' + time + '" name="atlas1_img[]" value=""/>' +
                    '<form action="?do=Atlas" enctype="multipart/form-data" method="post" target="upframe" class="form-inline">' +
                    '<div class="input-group" style="margin: 1px 0px">' +
                    '<div class="input-group-addon">选择图片</div>' +
                    '<div class="atlas_img_div form-group" style="position: relative">' +
                    '<img id="atlas_img_' + time + '" src="" alt="" style="max-width: 360px;max-height: 240px"/>' +
                    '<div class="form-group atlas1_img_div div-child-left">' +
                    '<input type="hidden" name="atlas" value="fileimg_' + time + '">' +
                    '<input style="width: 360px; height: 240px" type="file" class="form-control input-file" name="fileimg_' + time + '" id="fileimg_' + time + '" onchange="$(this).parents(\'form\').submit();"/>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</form>' +
                    '<div class="input-group" style="margin: 1px 0px">' +
                    '<div class="input-group-addon">图片文字</div>' +
                    '<textarea style="width: 300px; height: 123px" type="text" class="form-control" name="atlas_text[]" id="atlas_text"></textarea>' +
                    '<div>' +
                    '<input type="button" class="btn btn-primary" value="新增" onclick="addAtlas($(this))" style="margin-top: 10px; margin-left: 5px"/>' +
                    '<input type="button" class="btn btn-default" value="删除" onclick="atlasdelCode($(this))" style="margin-top: 40px; margin-left: 5px"/>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>';
            if(type == 1) {
                $('#module_list').prepend(tpl);
            } else{
                obj.parent().parent().parent().parent().after(tpl);
            }
            set_up();
        }
        /**
         * 图集拖拽
         */
        var isadd = true;
        $(function(){
            var $list = $("#module_list");

            $list.sortable({
                opacity: 0.6,
                revert: true,
                cursor: 'move',
                handle: '.m_title',
                update: function(){
                    var new_order = [];
                    $list.children(".modules").each(function() {
                        new_order.push(this.title);
                    });
                }
            });
        });
        /**
         * 图集删除
         */
        function atlasdelCode(obj) {
            obj.parent().parent().parent().parent().remove();
        }

        /**
         * 添加
         */
        function addCode(obj) {
            var num = $('input[name="cover[]"]').size();
            if (num >= 3) {
                top.swal('出错了', '最多允许上传3张封面图', 'error');
                return false;
            }
            var time = new Date().getTime();
            var tpl =
                    '<div class="cover_img_div">' +
                    '<img id="preview_img_' + time + '" src="" style="width:auto;max-width:600px;height:160px;">' +
                    '<form action="?do=UploadImg&id=' + time + '" enctype="multipart/form-data" method="POST" target="upframe">' +
                    '<div class="input-group">' +
                    '<input type="hidden" name="file_name" value="fileimg_' + time + '">' +
                    '<input class="form-control" style="width: 99px;" type="file" name="fileimg_' + time + '" accept=".jpg,.png,.jpeg" onchange="fileChange(' + time + ')"> &nbsp;' +
                    '</div>' +
                    '</form>' +
                    '<a class="btn btn-default input-file" href="javascript:void(0);">选择图片</a>' +
                    '<a class="btn btn-default delete_btn" onclick="delCode($(this), ' + time + ')">删除</a>' +
                    '<input type="hidden" id="cover_' + time + '" name="cover[]" value="" />' +
                    '</div>';
            obj.parent().before(tpl);
            return time;
        }

        /**
         * 删除
         */
        function delCode(obj) {
            obj.parent().remove();
        }
        /**
         * 监听图片内容变动
         */
        function fileChange(index) {
            $("input[name=fileimg_" + index + "]").parents('form').submit();
        }
        /**
         * 图片上传回调函数
         */
        function _uploadImg(data) {
            if (typeof data == 'string') {
                data = eval('(' + data + ')');
            }

            if (data.status != 200) {
                top.swal('出错了', data.msg, 'error');
                return false;
            } else {
                data = data['data'];
                var index = data['file_name'].split("_")[1];
                $("#preview_img_" + index).attr('src', data['img_url']);
                $("#cover_" + index).val(data['img_url']);
            }
        }

        /**
         * 图集上传回调
         */
        function __uploadAtlas(data) {
            if (typeof data == 'string') {
                data = eval('(' + data + ')');
            }

            if (data.status != 200) {
                top.swal('出错了', data.msg, 'error');
                return false;
            } else {
                data = data['data'];
                var index = data['file_name'].split("_")[1];
                $("#atlas_img_" + index).attr('src', data['img_url']);
                $("#atlas1_img_" + index).val(data['img_url']);
            }
        }

        /**
         * 监听视频变动
         */
        function videoChange() {
            $("input[name=video]").parents('form').submit();
        }
        /**
         * 视频上传回调函数
         */
        function _uploadVideo(data) {
            if (typeof data == 'string') {
                data = eval('(' + data + ')');
            }

            if (data.status != 200) {
                top.swal('出错了', data.msg, 'error');
                return false;
            } else {
                data = data['data'];
                $("#TypeData").val(data['video_url']);
            }
        }

        function From_submit(btn) {
            $("#Type").attr("disabled",false);
            var btn = $(btn);
            if (btn.prop('disabled')) {
                return false;
            }
            $('#div_btn').find('input').prop('disabled', true);

            // fix img
            if (editor && editor.document) {
                var imgs = editor.document.getElementsByTag('img').$;
                for (var i = 0, len = imgs.length; i < len; i++) {
                    var img = imgs[i];
                    if (img.height > 0) {
                        img.setAttribute('data-height', img.height);
                    }
                    if (img.width > 0) {
                        img.setAttribute('data-width', img.width);
                    }
                }
            }

            var title, alias, type, typelen, typedata, tag, viewtag, content, error, urlfrom, uri, tata;
            title = $("#Title").val();
            //alias = $("#Alias").val();
            type = $("#Type").val();
            typelen = $("#TypeLen").val();
            typedata = $("#TypeData").val();
            tag = $("#tag").val();
            viewtag = $("#ViewTag").val();
            //content = editor.document.getBody().getHtml();
            content = editor.getData();
            urlfrom = $("#urlfrom").val();
            uri = $("#uri").val();
            tata = $("#TaTaUserId").val();
            error = '';

            if (trimStr(title) == '') {
                error += "标题不能为空！\r\n";
            }
            if (trimStr(type) == '') {
                error += "文章类型不能为空！\r\n";
            }
            if (type == 3) {
                if (trimStr(typelen) == '' || trimStr(typedata) == '') {
                    error += "视频时长与链接地址不能为空！\r\n";
                }
            }
            if (type == 1 && trimStr(content) == '') {
                error += "内容不能为空！\r\n";
            }
            if (trimStr(tag) == '') {
                error += "标签不能为空！\r\n";
            }
            if (trimStr(viewtag) == '') {
                error += "展示标签不能为空！\r\n";
            }
            if (!trimStr(tata)) {
                error += "所属她她号不能为空！\r\n";
            }

	        //敏感词检测
	        var status = $("input[name=Status]:checked").val();
	        if (type == 1 && status == 1){
		        var title_match = title.match(sensitiveWord);
		        if (title_match != null && title_match.length > 0){
			        error += "文章标题含有敏感词："+title_match[0]+"！\r\n";
		        }

//		        var content_match = content.match(sensitiveWord);
//		        if (content_match != null){
//			        error += "文章内容含有敏感词："+content_match[0]+"！\r\n";
//		        }
	        }

            if (error != '') {
                $('#div_btn').find('input').prop('disabled', false);
                top.sweetAlert('数据不符合规范,禁止提交。', error, 'error');
                return false;
            } else {
                $('#Content').val(content);
                $('form').remove();
                $('#myformtable').wrap('<form id="form_main" enctype="multipart/form-data" method="post" action="?do=Update"></form>');
                $('#form_main').submit();
                return false;
            }
        }

       //下载第三方图片
        $('#picture_info').click(function (){
            var content = editor.getData();
            var path = content.match(/<img.*src="(.+)"[^>]*>/g);

            if (path) {
                var state = 0;
                for (var i = 0; i < path.length; i++) {
                    if (path[i].indexOf('qbtoutiao.com') == -1) {
                        state = 1;
                    }
                }
            } else {
                top.swal({
                    title: "内容中没有图片",
                    text: "请加载图片",
                    showConfirmButton: true
                });
                return false;
            }

            if (state != 1) {
                top.swal({
                    title: "内容中没有第三方图片",
                    text: "请加载第三方图片",
                    showConfirmButton: true
                });
            } else {
                top.swal({
                    title: "第三方图片正在下载",
                    text: "请不要关闭浏览器",
                    showConfirmButton: false
                });
                $.post("?do=Picinfo", {'content': content}, function (data) {
                    if (data.type == 'success') {
                        top.swal(
                            '下载完成',
                            "成功：" +data.success_count + "失败：" + data.error_count,
                            'success'
                        );
                        editor.setData(data.content);
                    }
                }, 'json');
            }
        });

        //预览文章内容
        function preview(interlinkage) {
            var tpl =
                    '<div align="center" style="background: url(\'http://admin.qbtoutiao.com/public/images/preview.png\') center -244px;height:648px;padding-top:76px;"><iframe id="pixel1" style="width: 280px;height: 495px" src="' + interlinkage + '"></iframe></div>';
            top.$('#adminModalBody').html(tpl);
            top.$('#adminModal').show();
        }

        //去除字符串首尾空格
        function trimStr(str) {
            return str.replace(/(^\s*)|(\s*$)/g, "");
        }

        //上传封面
        function callRequest(sel) {
            var picturenumber = addCode($('#add_cover'));
            if (picturenumber != false) {
                jQuery.post("?do=UploadImg", {'sel': sel}, function (data) {
                    if (data.status != 200) {
                        $('#cover_'+picturenumber).parent().remove();
                        if (data.msg == '图片尺寸不符合！') {
                            data.msg += '最小需要320*240';
                        }
                        top.swal('出错了_fx', data.msg, 'error');
                        return false;
                    } else {
                        data = data['data'];
                        $("#preview_img_" + picturenumber).attr('src', data['img_url']);
                        $("#cover_" + picturenumber).val(data['img_url']);
                    }
                }, 'json');
            }
        }

        var editor = CKEDITOR.replace('Content', {
            language: 'zh-cn',
            customConfig: '',
            height: "500px",
            //allowedContent: 'p[*]; b; a[*]; img[*]; br',
            allowedContent: true,
            extraPlugins: 'justify,html5video,autoformat,panelbutton,colorbutton,colordialog,font',
            toolbar: [
                ['Source', '-', 'Save', 'NewPage', 'DocProps', 'Preview', 'Print', '-', 'Templates', 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo', 'Find', 'Replace', '-', 'SelectAll', '-', 'SpellChecker', 'Scayt', 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField', '/', 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat', 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', 'Link', 'Unlink', 'Anchor', 'Html5video', 'Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak', 'Iframe', 'Autoformat', '/', 'Styles', 'Format', 'Font', 'FontSize', 'TextColor', 'BGColor', 'Maximize', 'ShowBlocks']
                //['Undo', 'Redo', 'Cut', 'Copy', 'Paste', 'PasteText', 'Maximize', 'Source', '-', 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock', '-', 'Link', 'Unlink', 'Image']
            ]
        });
        CKFinder.setupCKEditor(editor, {basePath: '/public/editor/ckfinder/'});

        //添加右键菜单选项
        editor.on('instanceReady', function (e) {
            editor.addCommand("setCover", {
                exec : function( editor )
                {
                    //获取图片的路径
                    var sel = editor.getSelection().getSelectedElement();
                    callRequest(sel.getAttribute('src'));
                }
            });

            editor.contextMenu.addListener( function( element, selection ) {
                if (element.getName) {
                    var name = element.getName();
                    if (name === 'img') {
                        return {
                            setCover : CKEDITOR.TRISTATE_ON
                        };
                    }
                }
                return null;
            });

            editor.addMenuItems({
                setCover : {
                    label : '设为封面',
                    command : 'setCover',
                    group : 'image',
                    icon: 'image',
                    order : 1
                }
            });
        });

        //图集右键设为封面图
        $(document).ready(function() {
            set_up();
        });
        function set_up() {
            $('.atlas_img_div').contextMenu('myMenu1',{
                bindings:{
                    'open': function(t){
                        var sel =  $(t).find('img').attr('src');
                        if (sel) {
                            callRequest(sel);
                        } else {
                            top.swal('图片为空','不能设为封面图','error');
                        }
                    }
                }
            });
        }

        // 文本域输入标签提示
        userAutoTips({id:'tag'});
        userAutoTips({id:'ViewTag'});
    </script>
{/literal}
</body>
</html>